package com.masterclient.app.businessmodule.homemodule.view.adapter.special;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.VirtualLayoutManager;
import com.masterclient.app.R;
import com.masterclient.app.businessmodule.homemodule.bean.homecms.HomeCmsIndexBean;
import com.masterclient.app.businessmodule.homemodule.view.holder.HomeViewHolder;
import com.eoner.baselibrary.utils.ScreenUtils;


public class HomePageXRemAdapter extends DelegateAdapter.Adapter<HomeViewHolder> {

    private Context mContext;
    private LayoutHelper mLayoutHelper;
    private VirtualLayoutManager.LayoutParams mLayoutParams;
    private int mCount = 0;
    private HomeCmsIndexBean sh_rem_collection;
    
    public HomePageXRemAdapter(Context context, LayoutHelper layoutHelper, int count) {
        this(context, layoutHelper, count, null,null);
    }

    public HomePageXRemAdapter(Context context, LayoutHelper layoutHelper, int count, @NonNull VirtualLayoutManager.LayoutParams layoutParams,HomeCmsIndexBean sh_rem_collection) {
        this.mContext = context;
        this.mLayoutHelper = layoutHelper;
        this.mCount = count;
        this.mLayoutParams = layoutParams;
        this.sh_rem_collection = sh_rem_collection;
    }
    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return mLayoutHelper;
    }
    @Override
    protected void onBindViewHolderWithOffset(HomeViewHolder holder, int position, int offsetTotal) {
    }

    @Override
    public HomeViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return null;
    }
    @Override
    public void onBindViewHolder(HomeViewHolder holder, int position) {
        if(mLayoutParams!=null) {
            holder.itemView.setLayoutParams(
                    new VirtualLayoutManager.LayoutParams(mLayoutParams));
        }

        View llRecommendBrand = holder.itemView.findViewById(R.id.ll_recommend_brand);
        ViewPager brandViewPager = holder.itemView.findViewById(R.id.brandViewPager);

        //专题精选
        if (sh_rem_collection != null &&
                sh_rem_collection.getList() != null &&
                sh_rem_collection.getList().size() > 0) {

            llRecommendBrand.setVisibility(View.VISIBLE);
            //tvRecommedBrand.setText(sh_rem_collection.getSh_title());
            RecommendBrandPagerAdapter recommendBrandPagerAdapter = new RecommendBrandPagerAdapter(mContext,  sh_rem_collection.getList(),brandViewPager);
            brandViewPager.setAdapter(recommendBrandPagerAdapter);
            brandViewPager.setClipToPadding(false);
            brandViewPager.setPageMargin(ScreenUtils.dp2px(-113));
            brandViewPager.setOffscreenPageLimit(2);

        } else {
            llRecommendBrand.setVisibility(View.GONE);
        }

    }

    @Override
    public int getItemCount() {
        return mCount;
    }

    @Override
    public int getItemViewType(int position) {
        return 10;
    }
}
